<?php if ( ! have_posts() ) :
?>
<div class="postmeta">
	<h1 class="title"><?php _e('Not Found', 'mt-white');?></h1>
	<p>
		<?php _e('Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'mt-white');?>
	</p>
</div>
<?php endif; wp_reset_query();?>

<?php if (have_posts()) : while (have_posts()) : the_post();
?>

<?php /* GALLERY */ if ( has_post_format( 'gallery' )) :
?>

<?php $images = get_children(array('post_parent' => $post -> ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999));
	if($images) :
		$total_images = count($images);
		$image = array_shift($images);
		$image_img_tag = wp_get_attachment_image($image -> ID, 'thumbnail');
	endif;
?>
<div <?php post_class('post') ?> >
	<h2 class="title"><a href="<?php the_permalink();?>" title="<?php printf(esc_attr__('Permalink to %s', 'mt-white'), the_title_attribute('echo=0'));?>" rel="bookmark"><?php the_title();?></a></h2>
	<a class="wp-post-image alignleft" href="<?php the_permalink();?>"><?php echo $image_img_tag;?></a>
	<ul class="postmeta">
		<li>
			<?php white_posted_on();?>
		</li>
		<li>
			<?php comments_popup_link(__('Leave a comment', 'mt-white'), __('1 Comment', 'mt-white'), __('% Comments', 'mt-white'));?>
		</li>
		<li>
			<br />
			<?php _e('Author', 'mt-white');?>:
			<?php the_author_posts_link();?>
		</li>
	</ul>
	<?php printf(__('<p>This gallery contains <a %1$s>%2$s photo</a>. </p>', 'mt-white'), 'href="' . get_permalink() . '" title="' . sprintf(esc_attr__('Permalink to %s', 'mt-white'), the_title_attribute('echo=0')) . '" rel="bookmark"', number_format_i18n($total_images));?>
	<?php the_excerpt();?>
	<?php wp_link_pages(array('before' => '<div class="page-link">' . __('Pages:', 'mt-white'), 'after' => '</div>'));?>
	<div class="clear"></div>
</div>
<?php /* IMAGE */ elseif ( 'image' == get_post_format( $post->ID ) ) :?>
<div <?php post_class('post') ?> >
	<div class="entry">
		<?php if ( post_password_required() ) :
		?>
		<?php the_content();?>
		<?php else :?>
		<?php    $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
if ( $images ) {
$total_images = count( $images );
$image = array_shift( $images );
$image_img_tag = wp_get_attachment_image( $image->ID, 'large' );
		?>
		<a class="wp-post-image" href="<?php the_permalink();?>" title="<?php the_title();?>"> <?php echo $image_img_tag;?></a>
		<?php } else {?>
		<a href="<?php echo the_permalink();?>" title="<?php printf(esc_attr__('Permalink to %s', 'mt-dark'), the_title_attribute('echo=0'));?>" rel="bookmark"> <?php
			if((function_exists('add_theme_support')) && ( has_post_thumbnail())) {
				the_post_thumbnail('large');
			}
		?></a>
		<?php }?>
		<?php endif;?>
			<h2 class="title"><a href="<?php the_permalink();?>" title="<?php printf(esc_attr__('Permalink to %s', 'mt-white'), the_title_attribute('echo=0'));?>" rel="bookmark"><?php the_title();?></a></h2>

	</div>
	<div class="clear"></div>
</div>
<?php /* ASIDE */ elseif ( 'aside' == get_post_format( $post->ID ) ) :?>

<div <?php post_class('post') ?> >
	<div class="entry">
		<?php the_content(__('(more...)', 'mt-white'));?>
	</div>
	<ul class="postmeta">
		<?php wp_link_pages(array('before' => '<li class="page-link">' . __('Pages:', 'mt-white'), 'after' => '</li>'));?>
		<li>
			<?php white_posted_on();?>
			<?php comments_popup_link(__('Leave a comment', 'mt-white'), __('1 Comment', 'mt-white'), __('% Comments', 'mt-white'));?> <?php edit_post_link(__('Edit This', 'mt-white'));?>
		</li>
	</ul>
</div>
<?php /* Link */ elseif ( 'link' == get_post_format( $post->ID ) ) :?>

<div <?php post_class('post') ?> >
	<div class="entry">
		<?php if ( post_password_required() ) :
		?>
		<div class="postmeta">
			<?php the_content();?>
		</div>
		<?php endif;?>
		<?php if (function_exists( 'white_link_format' )) {
		?>
		<h2 class="title"><a href="<?php echo white_link_format();?>" title="<?php printf(esc_attr__('%s', 'mt-white'), the_title_attribute('echo=0'));?>" rel="bookmark"> <?php the_title();?></a></h2><?php }?>
		<?php the_excerpt();?>
	</div>
	<ul class="postmeta">
		<?php wp_link_pages(array('before' => '<li class="page-link">' . __('Pages:', 'mt-white'), 'after' => '</li>'));?>
		<li>
			<?php white_posted_on();?>
			<?php comments_popup_link(__('Leave a comment', 'mt-white'), __('1 Comment', 'mt-white'), __('% Comments', 'mt-white'));?> <?php edit_post_link(__('Edit This', 'mt-white'));?>
		</li>
	</ul>
</div>
<?php  else :?>

<div <?php post_class('post') ?> >
	<?php
	if((function_exists('add_theme_support')) && ( has_post_thumbnail())) {
		the_post_thumbnail('single_post');
	}
	?>
	<h2 class="title"><a href="<?php the_permalink();?>" title="<?php printf(esc_attr__('Permalink to %s', 'mt-white'), the_title_attribute('echo=0'));?>" rel="bookmark"><?php the_title();?></a></h2>
	<?php if(is_search()) :
	?>
	<ul class="postmeta">
		<li>
			<?php white_posted_on();?>
		</li>
		<li>
			<?php comments_popup_link(__('Leave a comment', 'mt-white'), __('1 Comment', 'mt-white'), __('% Comments', 'mt-white'));?>,
		</li>
		<li>
			<?php _e('Author', 'mt-white');?>:
			<?php the_author_posts_link();?>
		</li>
	</ul>
	<?php else :?>
	<ul class="postmeta">
		<li>
			<?php white_posted_on();?>
		</li>
		<li>
			<?php comments_popup_link(__('Leave a comment', 'mt-white'), __('1 Comment', 'mt-white'), __('% Comments', 'mt-white'));?>,
		</li>
		<li>
			<?php _e('Author', 'mt-white');?>:
			<?php the_author_posts_link();?>
		</li>
		<li>
			<?php _e('Categories', 'mt-white');?>:
			<?php the_category(', ')
			?>
		</li>
		<?php the_tags('<li><br />' . __('Tags: ', 'mt-white'), ', ', '</li>');?>
	</ul>
	<?php endif;?>
	<?php if(is_search() || is_archive()) :
	?>
	<?php the_excerpt();?>
	<?php else :?>
	<?php the_content(__('(more...)', 'mt-white'));?>
	<?php endif;?>
	<?php wp_link_pages(array('before' => '<div class="page-link">' . __('Pages:', 'mt-white'), 'after' => '</div>'));?>

	<div class="clear"></div>
</div>
<?php endif;?>

<?php endwhile;  endif;?>
